<?php
namespace app\wechat\controller;

use app\api\service\Coupon;
use think\View;

class WCoupon extends WCommon
{
    // 获取订单可用优惠券
    public function index()
    {
        $order_id = input('param.order_id', 0);
        $model = input('param.model', '');
        $param['order_id'] = $order_id;
        $param['model'] = $model;
        //dump($param);
        $coupon = Coupon::member_get_usable_coupon_list($param);
        return json($coupon);
    }
    // 优惠券列表
    public function coupon_list() {
        // 统计优惠券数量
        $param = [
            'member_id' => session('member_id')
        ];
        $data = Coupon::coupon_num($param);
        $this->assign('data', $data['data']);
        return view();
    }

    public function get_coupon_list() {
        $status = input('param.status', 0);
        $param = [
            'member_id' => session('member_id'),
            'status' => $status
        ];
        $data = Coupon::get_coupon_list_by_status($param);
        if ($data['code'] == 200) {
            $view = new View();
            $view->assign('data', $data['data']);
            $view->assign('status', $status);
            $tpl = $view->fetch('w_coupon/coupon_list_tpl');
            $data['tpl'] = $tpl;
        }
        return json($data);
    }
}
